<template>
  <div class="background">
    <el-image
        style="background-color:rgb(184,229,248);background-size:cover;background-attachment: fixed;width: 100%;height: 100%;background-repeat:no-repeat;background-position:center;"
        :src=logo
        :fit="fit">
    </el-image></div>
  <img src="" class="logo" alt="">

  <div class="login-app">
    <!-- 选择登录方式部分 -->
    <div class="login-header" @click="checkRadio()">
      <input type="radio" name="login-opt" id="message" checked="checked">
      <label for="message" class="m-btn">短信登录</label>
      <input type="radio" name="login-opt" id="username">
      <label for="username" class="u-btn">账号登录</label>
      <input type="radio" name="login-opt" id="qrcode">
      <label for="qrcode" class="q-btn">扫码登录</label>
    </div>
    <!-- 登录表单部分 -->
    <div class="login-body">
      <div id="form-bar" name="form-bar">
        <form action="" class="m-form">
          <input type="text"  placeholder="请输入手机号码">
          <input type="text" placeholder="请输入验证码"><button class="vercode-btn">获取验证码</button>
          <input type="checkbox" name="" id="sure">
          <label for="sure" class="tobesure"><p>未注册手机登录时会自动创建新账号，我已阅读并同意<a href="">服务协议</a>和<a href="">隐私权条款</a></p></label>
          <button class="login-btn">登录</button>
        </form>
        <!-- 账号登录表单 -->
        <form action="" class="u-form">
          <input type="text" placeholder="请输入手机号码">
          <input type="text" placeholder="请输入验证码">
          <button class="login-btn">登录</button>
        </form>
        <!-- 扫码登录表单 -->
        <form action="" class="q-form">
          <div class="qrcode">
            <img src="qrcode.png" alt="">
          </div>
        </form>
        <!-- <form-append></form-append> -->
      </div>
    </div>
  </div>
</template>

<script>
import qs from 'qs'
import storeUtil from '../utils/localstorage'
import { User } from '@element-plus/icons-vue'
import  Logo from '../assets/123.png'
import { ref } from 'vue'
import '../css/login.css'
export default {
  components:{

  },
  name: "Login",
  data(){
    return{
      logo:Logo,
      loginData:{},
      rules:{
        username:{
          required: true,
          message:'请输入账号',
          trigger:'blur'
        },
        password:{
          required: true,
          message:'请输入密码',
          trigger:'blur'
        },
      },
      login_opt : document.getElementsByName('login-opt'),
      form_bar : document.getElementsByName('form-bar'),
    }
  },
  methods:{
    checkRadio(){
      console.log("form_bar",this.form_bar[0].style.transform);
      for(let i =0; i < this.login_opt.length; i++){
        if(this.login_opt[i].checked){
          this.form_bar[0].style.transform = 'translateX(' + (-348*i) + 'px)';
        }
      }
    },
    login(){
      if(!this.loginData.username || !this.loginData.password){
        // alert("");
        //已经全局加载了element-plus
        this.$message({message:"请输入账号和密码"})
        return;
      }
      let data = qs.stringify(this.loginData)
      this.$axios.post('/api/user/login',data)
      .then(data=>{
        if(data.code === 0) {
          let uid = data.user.id;
          let token = data.user.token;
          storeUtil.save('uid', uid);
          storeUtil.save('token', token);
          // this.$router.push({name:'index',params:{key:'value'}})
          // // this.$router.push("/?key=value");
          this.$router.push({path:'/'})
        }
          //在前端保存以上两个值，用
      }).catch(error=>{
        console.log(error);
      })
    }
  },

    setup() {
  const activeName = ref('first')


  return{activeName}
  }
}
</script>

<style scoped>
.background{
  width:100%;
  height:100%;  /**宽高100%是为了图片铺满屏幕 */
  z-index:-1;
  position: absolute;
  top:0;
  left:0;

}
.logo{
  width: 216px;
  margin-bottom: 60px;
}

.login-app{
  width: 348px;
  margin-bottom: 60px;
}

.login-header{
  display: flex;
}
.login-header input[type="radio"]{
  display: none;
}
.login-header label{
  background-color: #f5f5f6;
  font-size: 18px;
  color: rgba(37, 38, 43, .36);

  padding: 16px;
  text-align: center;
  width: 100%;


  cursor: pointer;
}
.login-header .m-btn{
  border-top-left-radius: 12px;
}
.login-header .q-btn{
  border-top-right-radius: 12px;
}

#message:checked + .m-btn,
#username:checked + .u-btn,
#qrcode:checked + .q-btn{
  background-color: #fff;
  color: #25262b;
  cursor: default;
}


.login-body{
  overflow: hidden;
  border-radius: 0 0 20px 20px;
  background-color: #fff;

  -webkit-border-radius: 0 0 20px 20px;
  -moz-border-radius: 0 0 20px 20px;
  -ms-border-radius: 0 0 20px 20px;
  -o-border-radius: 0 0 20px 20px;
}

#form-bar{
  display: flex;

  transition: transform .6s cubic-bezier(0.175, 0.885, 0.32, 1.275);


  -webkit-transition: transform .6s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  -moz-transition: transform .6s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  -ms-transition: transform .6s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  -o-transition: transform .6s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}



.login-body form{
  flex-shrink: 0;

  width: 100%;

  box-sizing: border-box;
  padding: 22px;

  position: relative;
}

.login-body input{
  outline: none;
  width: 100%;
  box-sizing: border-box;
  height: 46px;
  margin-bottom: 16px;
  background-color: rgba(39, 39, 41, .04);
  border: 1px solid transparent;
  border-radius: 8px;
  -webkit-border-radius: 8px;
  -moz-border-radius: 8px;
  -ms-border-radius: 8px;
  -o-border-radius: 8px;

  font-size: 14px;
  padding: 1px 12px;
  color: #25262b;
}
.login-body input::placeholder{
  color: rgba(37, 38, 43, .36);
}
.login-body input:focus{
  border: 1px solid rgba(99, 125, 255, .48);
  background-color: #fff;
}

.m-form .vercode-btn{
  padding: 4px 12px;
  border-radius: 6px;
  font-size: 14px;
  color: #637dff;
  background-color: transparent;
  border: 1px solid rgba(99, 125, 255, .24);

  position: absolute;
  right: 36px;
  margin: 8px 0;

  -webkit-border-radius: 6px;
  -moz-border-radius: 6px;
  -ms-border-radius: 6px;
  -o-border-radius: 6px;
}

.login-body .login-btn{
  width: 100%;
  height: 48px;
  border: none;
  border-radius: 10px;
  background: linear-gradient(
      129.12deg,
      #446dff,
      rgba(99, 125 ,255, .75)
  );

  color: #fff;
  font-size: 16px;

  margin-top: 16px;
  margin-bottom: 60px;
}

button{
  cursor: pointer;
}

.m-form #sure{
  display: none;
}
.m-form label.tobesure{
  position: absolute;
  border:  2px solid rgba(132, 133, 141, .2);
  box-sizing: border-box;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  cursor: pointer;

  left: 22px;
}
#sure:checked + label.tobesure{
  background-color: #637dff;
}

label.tobesure::after{
  content: '';
  border:  2px solid #fff;
  position: absolute;
  width: 6px;
  height: 3px;
  border-top: none;
  border-right: none;
  transform: translate(-50%, -50%) rotate(-45deg);

  top: 45%;
  left: 50%;


  -webkit-transform: translate(-50%,-50%) rotate(-45deg);
  -moz-transform: translate(-50%,-50%) rotate(-45deg);
  -ms-transform: translate(-50%,-50%) rotate(-45deg);
  -o-transform: translate(-50%,-50%) rotate(-45deg);
  -webkit-transform: translate(-50%,-50%) rotate(-45deg);
}

#sure:not(:checked) ~ .login-btn{
  opacity: .5;
  cursor: not-allowed;

}

label.tobesure{
  bottom: 45px;
}
label.tobesure p{
  margin: 0;
  margin-left: 20px;
  width: 280px;

  font-size: 12px;
  line-height: 1.5;
  color: rgba(37, 38, 43, .36);

  position: relative;
  bottom: 3px;

}
label.tobesure p a{
  text-decoration: none;
  color: #637dff;
  padding: 0 5px;
}

.qrcode{
  width: 128px;
  height: 128px;
  box-shadow: 0px 0px 1px 1px rgba(28, 28, 32, 0.05), 0px 8px 24px rgba(28, 28, 32, 0.12);
  padding: 8px;
  box-sizing: border-box;
  border-radius: 10px;

  position: absolute;
  transform: translate(-50%, -50%);
  top: 40%;
  left: 50%;

  -webkit-border-radius: 10px;
  -moz-border-radius: 10px;
  -ms-border-radius: 10px;
  -o-border-radius: 10px;
  -webkit-transform: translate(-50%, -50%);
  -moz-transform: translate(-50%, -50%);
  -ms-transform: translate(-50%, -50%);
  -o-transform: translate(-50%, -50%);
}
.qrcode img{
  width: 100%;
}
</style>
